package org.pro.core.validateCode.processor;


import java.util.Map;

import org.pro.core.validateCode.ValidateCodeException;
import org.pro.core.validateCode.ValidateCodeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * 验证码处理的收集处理
 * @author luoqiz
 *
 */
@Component("validateCodeProcessorHolder")
public class ValidateCodeProcessorHolder {

	/**
	 * 收集系统中{@link ValidateCodeProcessor}接口的实现
	 */
	@Autowired
	private Map<String, ValidateCodeProcessor> validateCodeProcessors;

	public ValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type) {
		return findValidateCodeProcessor(type.toString().toLowerCase());
	}

	public ValidateCodeProcessor findValidateCodeProcessor(String type) {
		String name = type.toLowerCase() + ValidateCodeProcessor.class.getSimpleName();
		ValidateCodeProcessor processor = validateCodeProcessors.get(name);
		if (processor == null) {
			throw new ValidateCodeException("验证码处理器" + name + "不存在");
		}
		return processor;
	}

}
